# The Flutter tooling requires that developers have CMake 3.10 or later
# installed. You should not increase this version, as doing so will cause
# the plugin to fail to compile for some customers of the plugin.
cmake_minimum_required(VERSION 3.10)

project(napi_library VERSION 0.0.1 LANGUAGES C)

add_library(napi SHARED
  "dartnapi.c"
  "third_party/dartnapi_bridge.c"
  "napi_module_dartnapi.c"
  "third_party/global_napi_env.c"
)

set_target_properties(napi PROPERTIES
  PUBLIC_HEADER dartnapi.h
  OUTPUT_NAME "dartnapi"
)

target_compile_definitions(napi PUBLIC DART_SHARED_LIB)

# Ensure N-API headers are discoverable. Prefer SDK paths provided by OHOS toolchain.
include_directories(
  ${CMAKE_CURRENT_LIST_DIR}/third_party
  $ENV{OHOS_NDK_HOME}/sysroot/usr/include
  $ENV{OHOS_SDK_HOME}/native/sysroot/usr/include
)

if (ANDROID)
  # Support Android 15 16k page size
  target_link_options(napi PRIVATE "-Wl,-z,max-page-size=16384")
endif()

# Link HarmonyOS N-API system library to resolve napi_* symbols
find_package(Threads REQUIRED)
target_link_libraries(napi PUBLIC ace_napi.z Threads::Threads)
